from openai import OpenAI
import os
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from mcp.client.sse import sse_client
from duckduckgo_search import DDGS
client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY", ""),
    base_url=os.environ.get("OPENAI_BASE_URL", "")
)
def call_llm(prompt):    
    # client = OpenAI(
    #     api_key=os.environ.get("OPENAI_API_KEY", ""),
    #     base_url=os.environ.get("OPENAI_BASE_URL", "")
    # )

    # Make a streaming chat completion request
    r = client.chat.completions.create(
         model="Qwen3-235B-A22B-1874024892354772993",
         messages=[
                {"role": "user", "content": prompt}
            ],
    )
    return r.choices[0].message.content


if __name__ == "__main__":
    print("## Testing call_llm")
    prompt = "In a few words, what is the meaning of life?"
    print(f"## Prompt: {prompt}")
    response = call_llm(prompt)
    print(f"## Response: {response}")
    
def search_web(query):
    results = DDGS().text(query, max_results=5)
    # Convert results to a string
    results_str = "\n\n".join([f"Title: {r['title']}\nURL: {r['href']}\nSnippet: {r['body']}" for r in results])
    return results_str
